package work;

import work.topo.*;
import mpi.*;
import org.picocontainer.Parameter;
import org.picocontainer.parameters.ConstantParameter;
import org.picocontainer.parameters.ComponentParameter;

public class Main {
	private Configurator cfg;
	private Communicator comm;
	

	private void init(String argv[]) throws Exception {
		cfg = Configurator.cfg();
		initMPI(argv);

		//System.out.println(cfg);
		//System.out.println(comm);
	}

	public void initMPI(String args[]) throws Exception {
		MPI.Init(args);

		int me = MPI.COMM_WORLD.Rank();
		int size = MPI.COMM_WORLD.Size();

		ConstantParameter p[] = new ConstantParameter[2];
		p[0] = new ConstantParameter(me);
		p[1] = new ConstantParameter(size);

		cfg.register(UniDirectionRingProcessTopologyImpl.class, p);
		cfg.register(Communicator.class);

		comm = cfg.get(Communicator.class);

		comm.work();
	}

	public void exitMPI() throws Exception {
		MPI.Finalize();
	}
	
	public static void main(String argv[]) throws Exception {
		
		Main worker = new Main();
		worker.init(argv);

		worker.exitMPI();
	}
}
